﻿using System;
using CCL.SocketMessage;
using CCL.SocketMessage.Request;

namespace TestClient
{
    class Program
    {
        static Connector m_connector = new Connector();

        static void Main(string[] args)
        {
            CCL.TableStructure.User user = null;

            {
                Login login = new Login("test", "test");
                Message sendMsg = Message.MessageRequestBuilder(login);

                Message recvMsg = m_connector.Execute(sendMsg.GetByte());

                CCL.SocketMessage.Response.Login loginBody = (CCL.SocketMessage.Response.Login)recvMsg.Body;

                if (loginBody.Result == Constant.Result.Success)
                {
                    Console.WriteLine(loginBody.UserInfo.Name);
                    user = loginBody.UserInfo;
                }
                else
                {
                    Console.WriteLine(loginBody.ErrorMessage);
                }
            }
            {
                Join join = new Join("test2", "test2", "박병훈");
                Message sendMsg = Message.MessageRequestBuilder(join);

                Message recvMsg = m_connector.Execute(sendMsg.GetByte());

                CCL.SocketMessage.Response.Join body = (CCL.SocketMessage.Response.Join)recvMsg.Body;

                if (body.Result == Constant.Result.Success)
                {
                    Console.WriteLine("가입성공");
                }
                else
                {
                    Console.WriteLine(body.ErrorMessage);
                }
            }
            {
                RegistProject registProject = new RegistProject("testProject", user.UserID);
                Message sendMsg = Message.MessageRequestBuilder(registProject);

                Message recvMsg = m_connector.Execute(sendMsg.GetByte());

                CCL.SocketMessage.Response.RegistProject body = (CCL.SocketMessage.Response.RegistProject)recvMsg.Body;

                if (body.Result == Constant.Result.Success)
                {
                    Console.WriteLine(body.Project.ProjectName);
                }
                else
                {
                    Console.WriteLine(body.ErrorMessage);
                }
            }
        }
    }
}
